package com.moqianfan.mcuassistant.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.moqianfan.mcuassistant.bean.User;
import com.moqianfan.mcuassistant.comm.AppConfig;
import com.moqianfan.mcuassistant.comm.Common;
import com.umeng.analytics.MobclickAgent;

import butterknife.ButterKnife;
import cn.bmob.v3.BmobUser;

/**
 * Created by limh on 2017/3/7.
 * 基类Activity
 */

public abstract class BaseActivity extends AppCompatActivity {
    public AppConfig appConfig;
    public SharedPreferences userPreference;
    public User user;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        findViews();
        appConfig = AppConfig.getAppConfig();
        userPreference = getSharedPreferences(Common.SP_USER, MODE_PRIVATE);
        ButterKnife.bind(this);
        user= BmobUser.getCurrentUser(User.class);
        initViews();
        initDatas();
    }

    public abstract void findViews();

    public abstract void initViews();

    public abstract void initDatas();

    public void sendMsg(String msg, int what, Handler handler) {
        Bundle bundle = new Bundle();
        bundle.putString("msg", msg);
        Message message = new Message();
        message.what = what;
        message.setData(bundle);
        handler.sendMessage(message);
    }

    public void showToastShort(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

    public void showToastLong(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
    }

    public void openActivity(Class<?> calss) {
        Intent intent = new Intent();
        intent.setClass(this, calss);
        startActivity(intent);
    }

    public void openService(Class<?> calss) {
        Intent intent = new Intent();
        intent.setClass(this, calss);
        startService(intent);
    }

    public void stopService(Class<?> calss) {
        Intent intent = new Intent();
        intent.setClass(this, calss);
        stopService(intent);
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }
}
